package Stack;

import java.util.Stack;

public class test extends MyStack<Number> {

    //出栈入栈次序匹配
    public  boolean IsPopOrder(int []pushV,int []popV){
        Stack<Integer> stack=new Stack<>();
        int j=0;
        for(int i=0;i< pushV.length;i++){
            stack.push(pushV[i]);
            while(!stack.isEmpty() && j<popV.length && stack.peek()==popV[j]){
                stack.pop();
                j++;
            }

        }
        return stack.isEmpty();
    }

    //括号匹配
    public  boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < stack.size(); i++) {
            char ch = s.charAt(i);
            if (ch == '(' || ch == '[' || ch == '{') {
                stack.push(ch);
            }else {
                char peekCh = stack.peek();
                if (peekCh == '(' && ch == ')' || peekCh == '{' && ch == '}' || peekCh == '[' && ch == ']') {
                    stack.pop();
                } else {
                    return false;
                }
            }
        }
        if(!stack.isEmpty()){
            return false;
        }
        return true;
    }

    //逆波兰表达式
    public int evaLRPN(String[] tokens){
        Stack<Integer> stack=new Stack<>();
        for(int i=0;i<stack.size();i++){
            String s=tokens[i];
            if(isOpreation(s)){
                //如果是数字，那么将他转为Integer存入栈中
                Integer ret =Integer.valueOf(s);
                stack.push(ret);
            }else{
                Integer val1=stack.pop();
                Integer val2=stack.pop();
                switch (s){
                    case "+":
                        stack.push(val1+val2);
                        break;
                    case "-":
                        stack.push(val1-val2);
                        break;
                    case "*":
                        stack.push(val1*val2);
                        break;
                    case "/":
                        stack.push(val1/val2);
                        break;
                }
            }
        }
        return stack.pop();
    }

    public boolean isOpreation(String val){
        if(val.equals("+") ||val.equals("-") ||val.equals("*") ||val.equals("/") ){
            return true;
        }
        return false;
    }





    public static void main1(String[] args) {
        Stack <Integer> stack=new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        Integer val1=stack.pop();
        Integer val2=stack.pop();
        System.out.println(val1);
        System.out.println(val2);
        Integer n= stack.pop();
        Integer n1=stack.peek();
        System.out.println(stack.empty());
        System.out.println(n1);
        System.out.println(n);
        System.out.println(stack.size());
        MyStack <Integer> myStack= new MyStack<>();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
        myStack.push(5);
        System.out.println(myStack.size());
        System.out.println(myStack.pop());
        myStack.pop();
        System.out.println(myStack.peek());
    }
}
